package com.xonro.common.histrans.sfeg.job.update.contarct;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.schedule.IJob;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.consts.SfegConst;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.List;

public class UpdateContractRecordInfo implements IJob {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        SDK.getLogAPI().consoleInfo("开始更细合同档案");
        String sql = "SELECT ID ,CONTRACT_NO FROM  BO_XR_MDM_CONTRACT";

        List<RowMap> maps = DBSql.getMaps(sql);

        for (RowMap m : maps) {
            String id = m.getString("ID");
            String contractNo = m.getString("CONTRACT_NO");

            String ccSql = "SELECT * FROM tb_ContractInfo c LEFT JOIN tb_ContractSignatory s ON c.ctCode=s.ctCode WHERE c.belongCorp = '1040' AND c.HTBH='" + contractNo + "'";
            List<RowMap> ccMaps = SDK.getCCAPI().getRDSAPI(SfegConst.CCID).getMaps(ccSql);
            for (RowMap cc : ccMaps) {
                String qylx = cc.getString("qylx");
                String signDept = cc.getString("signDept");

                String signdeptname = cc.getString("signdeptname");
                StringBuilder sb = new StringBuilder("UPDATE BO_XR_MDM_CONTRACT SET  ");
                if ("1".equals(qylx)) {

                    sb.append("A_COMPANY_NO='" + signDept + "' ");

                } else if ("2".equals(qylx)) {
                    sb.append("B_COMPANY_NO='" + signDept + "' ");

                } else if ("3".equals(qylx)) {
                    sb.append("C_COMPANY_NO='" + signDept + "' ");


                } else if ("4".equals(qylx)) {
                    sb.append("D_COMPANY_NO='" + signDept + "' ");

                }
                sb.append(" WHERE ID='" + id + "'");
                SDK.getLogAPI().consoleInfo("更细合同档案sql=" + sb.toString());
                DBSql.update(sb.toString());

            }
        }

        SDK.getLogAPI().consoleInfo("结束更细合同档案");
    }
}
